package it.ap.sa.core.dao.util;

import com.fasterxml.jackson.annotation.JsonFormat;

/*
 *  
    "equals"			exactly equal to
	"notEqual"			not equal to
	"greaterThan"		Greater than
	"lessThan"			Less than
	"greaterOrEqual"	Greater than or equal to
	"lessOrEqual"		Less than or equal to
	"contains"			Contains as sub-string (match case)
	"startsWith"		Starts with (match case)
	"endsWith"			Ends with (match case)
	"iContains"			Contains as sub-string (case insensitive)
	"iStartsWith"		Starts with (case insensitive)
	"iEndsWith"			Ends with (case insensitive)
	"notContains"		Does not contain as sub-string (match case)
	"notStartsWith"		Does not start with (match case)
	"notEndsWith"		Does not end with (match case)
	"iNotContains"		Does not contain as sub-string (case insensitive)
	"iNotStartsWith"	Does not start with (case insensitive)
	"iNotEndsWith"		Does not end with (case insensitive)
	"regexp"			Regular expression match
	"iregexp"			Regular expression match (case insensitive)
	"isNull"			value is null
	"notNull"			value is non-null. Note empty string ("") is non-null
	"inSet"				value is in a set of values. Specify criterion.value as an Array
	"notInSet"			value is not in a set of values. Specify criterion.value as an Array
	"equalsField"		matches another field (specify fieldName as criterion.value)
	"notEqualField"		does not match another field (specified fieldName as criterion.value)
	"and"				all subcriteria (criterion.criteria) are true
	"not"				all subcriteria (criterion.criteria) are false
	"or"				at least one subcriteria (criterion.criteria) is true
	"between"			shortcut for "greaterThan" + "lessThan" + "and". Specify criterion.start and criterion.end
	"betweenInclusive"	shortcut for "greaterOrEqual" + "lessOrEqual" + "and". Specify criterion.start and criterion.end
 *
 */
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
public enum OperatorRestriction {
	
	 EQUALS("equals"),
	 NOT_EQUALS("notEquals"),
	 GREATER_THAN("greaterThan"),
	 LESS_THAN("lessThan"),
	 LESS_OR_EQUAL("lessOrEqual"),
	 GREATER_OR_EQUAL("greaterOrEqual"),
	 CONTAINS("contains"),
	 STARTS_WIDTH("startsWith"),
	 ENDS_WIDTH("endsWith"),
	 ICONTAINS("iContains"),
	 ISTARTS_WIDTH("iStartsWith"),
	 IENDS_WIDTH("iEndsWith"),
	 NOT_CONTAINS("notContains"),
	 NOT_STARTSWIDTH("notStartsWith"),
	 NOT_ENDS_WIDTH("notEndsWith"),
	 INOT_CONTAINS("iNotContains"),
	 INOT_STARTSWITH("iNotStartsWith"),
	 REGEXP("regexp"),
	 IREGEXP("iregexp"),
	 IS_NULL("isNull"),
	 IS_NOT_NULL("notNull"),
	 IN_SET("inSet"),
	 NOT_INSET("notInSet"),
	 EQUALS_FIELD("equalsField"),
	 NOT_EQUALS_FIELD("notEqualField"),
	 AND("and"),
	 NOT("not"),
	 OR("or"),
	 BETWEEN("between"), 
	 BETWEEN_INCLUSIVE("betweenInclusive"),
	 LIKE("like"),
	 ILIKE("ilike");
	 
	 private final String operator;
	 
	 OperatorRestriction(String operator){
		 this.operator=operator;
	 }
	 
	 public String getOperator(){
		 return this.operator;
	 }
	 
	 // ritorna un oggetto OperatorDaoId dalla string dell'operazione ritornata dal client
	 public static OperatorRestriction findFromValue(String operation){
		 OperatorRestriction ret =null;
		 for (OperatorRestriction p : OperatorRestriction.values()){
			 if(p.operator.equals(operation)){
				 ret = p;
				 break;
			 }
		 }
		 return ret;
	 }
}
